#include "igslib_irtc_timer.h"
#include "igslib_iutil.h"

namespace igslib
{
    namespace rtc_sample
    {
        /*!
         * It demostrates how to get time information from device.
         *
         * In runtime, it will show current time info by 1000 ms accumulated by system clock.
         * User should confirm the RTC timer's infomation is correct.
         */
        static void GetTime()
        {
            IRTCTimerManager* mgr = GetRTCTimerManagerInstance();
            IRTCTimer* rtc = mgr->NewM01RTCTimer();
            size_t last = util::GetTicks();
            while(util::KbHit() != 27)
            {
                size_t now = util::GetTicks();
                if (now < last)
                {
                    continue;
                }
                size_t delta = now - last;
                if (delta < 1000)
                {
                    continue;
                }
                struct tm ct = rtc->GetTime();
                printf("@%s>%04d:%02d:%02d,%02d:%02d:%02d,delta=%d\n",__func__,
                        ct.tm_year,ct.tm_mon,ct.tm_mday,
                        ct.tm_hour,ct.tm_min,ct.tm_sec,
                        delta);
                last = now;
            }
            delete mgr;
        }
    };
};
